/*
 * Copyright (C) 2016-2017 AnStudio
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.astudio.lhasa.modules.views;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.astudio.lhasa.R;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

@EViewGroup(R.layout.layout_interpreter_textview)
public class InterpreterTextView extends LinearLayout {
    @ViewById(R.id.text)
    TextView mText;
    @ViewById(R.id.left_banner)
    ViewGroup mLeftBanner;
    @ViewById(R.id.right_banner)
    ViewGroup mRightBanner;

    public InterpreterTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setType(boolean isAnchorLeft) {
        if (isAnchorLeft) {
            mRightBanner.setVisibility(INVISIBLE);
        } else {
            mText.setGravity(Gravity.CENTER_VERTICAL| Gravity.RIGHT);
            mLeftBanner.setVisibility(INVISIBLE);
        }
    }

    public void setText(String text, boolean isAppend) {
        if (isAppend) {
            mText.append(text);
        } else {
            mText.setText(text);
        }
    }

    public String getText() {
        return mText.getText().toString();
    }
}
